package org.apache.sad.core.framework.exception;

import java.io.Serializable;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * Represents an error message assoicated with ApplicationException and SystemException.
 * 
 */
public class Message implements Serializable {

    private static final long serialVersionUID = 1L;

    private String code;
    private String text;
    private Object[] args; 
    private String defaultMessage;

    public Message() {
    }

    public Message(String code, Object[] args) {
    	this(code, args, null);
    }
    
    public Message(String code) {
    	this(code, null, null);
    }
    
    public Message(String code, Object[] args, String defaultMessage) {
    	this.code = code;
    	this.args = args;
    	this.defaultMessage = defaultMessage;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

  
    public Object[] getArguments() {
        return args;
    }

  
    public void setArguments(Object[] value) {
        this.args = value;
    }

    public String getDefaultMessage() {
    	return defaultMessage;
    }

    public String toString() {
        ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
        builder.append("code", code);
        
        if ( text != null ) {
        	builder.append("text", text);
        } else if ( args != null && args.length > 0 ) {
        	builder.append("args", args);
        }
        if ( defaultMessage != null ) {
        	builder.append("defaultMessage", defaultMessage);
        }
        return builder.toString();
    }

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}
}
